package gzc.ssh.action;

import java.util.Map;

import gzc.ssh.model.Employee;
import gzc.ssh.service.IEmployeeService;

import javax.annotation.Resource;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class userAction extends ActionSupport {

	private String id;
	private String pwd;
//	@Resource
	private IEmployeeService employeeService;
	
	public void setEmployeeService(IEmployeeService employeeService) {
		this.employeeService = employeeService;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public String loginAction() throws Exception {
		System.out.println("id=" + id + ", pwd=" + pwd);		

		final Employee loginEmployee = (Employee)employeeService.findById(Employee.class, Integer.parseInt(id));
		if(null != loginEmployee){
			final Map<String, Object> session = (Map<String, Object>) ActionContext.getContext().getSession();		
			session.put("user", loginEmployee);
			return SUCCESS;
		}		
		return ERROR;
	}

}
